<?php

namespace App\Channels;

use Illuminate\Notifications\Notification;
use GuzzleHttp\Client;

class RobotChannel
{
    /**
     * 发送指定的通知。
     *
     * @param  mixed  $notifiable
     * @param  \Illuminate\Notifications\Notification  $notification
     * @return void
     */
    public function send($notifiable, Notification $notification)
    {
        $message = $notification->toWechatRobot($notifiable);

        $url = env('WEBHOOK_URL');
        if($url){
            $client = new Client();
            $res = $client->request('POST', $url, [
                'headers' => ['Content-Type' => 'application/json'],
                'json' => [
                    'msgtype' => 'text',
                    'text' => [
                        'content' => $message,
                    ],
                ],
                'timeout' => 3,
            ]);
            return json_decode($res->getBody(),true);
        }
    }

}
